<?php
session_start();
include('GMApi/GMApi.php');

@include_once("account.php");
$email = (defined("GM_EMAIL") ? GM_EMAIL : "your gmail account");
$password = (defined("GM_PASSWORD") ? GM_PASSWORD : "your gmail password");
$mac_address = (defined("GM_MACADDRESS") ? GM_MACADDRESS : "your mac address"); // xx-xx-xx-xx-xx

$api = new GMApi();
$api->setDebug(true);
$api->enableRestore(true);
$api->enableMACAddressCheck(true);
$api->enableSessionFile(true);

if(!$api->login($email, $password, $mac_address)) {
	die("login fail");
}

echo "This login is using ".$api->getLoginResultType()."<br/>";

$songs = $api->get_all_songs();
if($songs == false) {
	die("unable get songs");
}

?>
<table border="1">
	<tr>
		<td>Title</td>
		<td>Stream URL</td>
		<td>Download URL</td>
	</tr>

<?php
GMAPIUtils::flushOutput();
$result = array();
foreach($songs as $song) {
	$title = $song['title'];
	$songid = $song['id'];
	$stream_url = $api->get_stream_url($songid);
	if($stream_url == false)
		$stream_url = "error";
	else
		$stream_url = '<a href="'.$stream_url.'" target="_blank">stream</a>';
	
	$download_url = $api->get_download_info($songid);
	if($download_url == false)
		$download_url = "error";
	else if($download_url['url'] == null) 
		$download_url = 'downloaded '.$download_url['count'].' times';
	else
		$download_url = '<a href="'.$download_url['url'].'" target="_blank">download</a>('.$download_url['count'].')';
?>
	<tr>
		<td><?php echo $title; ?></td>
		<td><?php echo $stream_url ?></td>
		<td><?php echo $download_url ?></td>
	</tr>

<?php
	GMAPIUtils::flushOutput();
}
?>

</table>
no more songs